package main

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)


func SearchAvailableCodeCount(giftId int, d *gorm.DB) int {
	var count int
	err := d.Raw("select count(*) from lt_codes where sys_status = 0").Scan(&count).Error
	if err != nil {
		fmt.Println("err = ", err)
	}
	return count
}


func ce() {
	a := []int {1, 2, 3}
	change(&a)
	fmt.Println(a)
}

func change (a *[]int) {
	// 起作用
	(*a)[1] = 100
	// 起作用, 连贯了写就是 *a = append(*a, 4)
	temp := append(*a, 4)
	*a = temp
}

var db *gorm.DB

func Init() (err error) {
	//	viper.GetString("mysql.user"), viper.GetString("mysql.password"), viper.GetString("mysql.host"),
	//	viper.GetString("mysql.port"), viper.GetString("mysql.lottery"),
	//	)
	dsn := "root:123456@tcp(127.0.0.1:3306)/bluebell?parseTime=true&loc=Local"
	db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		return err
	}
	return err
}



func main() {
	Init()
	var password string
	rst := db.Table("users").Select("password").Where("username = ?", "张").Scan(&password)
	a := rst.RowsAffected
	fmt.Println(a)
	//ce()
	//dsn := "root:123456@tcp(127.0.0.1:3306)/lottery?charset=utf8mb4&parseTime=True&loc=Local"
	//instance, _ := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	//rst := SearchAvailableCodeCount(4, instance)
	//fmt.Println(rst)
	//a, b := 1, 2
	//var c float32
	//c = float32(a) / float32(b)
	//
	//fmt.Println(c, reflect.TypeOf(c), c)
	//s1 := []int{1, 2, 3, 4 }
	//fmt.Printf("s1= %v, len(s1)=%d, cap(s1)= %d\n", s1, len(s1), cap(s1))
	//s1 = s1[1:]
	//fmt.Printf("s1= %v, len(s1)=%d, cap(s1)= %d\n", s1, len(s1), cap(s1))
	//
	//arr := [...]int {1, 2, 3, 4 ,5 ,6 ,7 ,8}
	//s1 = arr[2:6]
	//fmt.Printf("s1= %v, len(s1)=%d, cap(s1)= %d\n", s1, len(s1), cap(s1))
	//arr := [...]int {1, 2, 3, 4 ,5 ,6 ,7 ,8}
	//s1 := arr[2:6]
	//fmt.Printf("s1= %v, len(s1)=%d, cap(s1)= %d\n", s1, len(s1), cap(s1))
	//s2 := append(s1, 10)
	//s3 := append(s2, 11)
	//s4 := append(s3, 12)
	//s5 := append(s4, 13)
	//s4[1] = 100  // 这里输入100
	//fmt.Printf("s4= %v, len(s4)=%d, cap(s4)= %d\n", s4, len(s4), cap(s4))
	//fmt.Println(s1)
	//fmt.Println(s2)
	//fmt.Println(s3)
	//fmt.Println(s4)
	//fmt.Println(s5)
	//fmt.Println(arr)
	//fmt.Println(&s1 == &s2)
	//s := "cds"
	//if s[0] > 'a' {
	//	fmt.Println(s[0])
	//	fmt.Println(1111)
	//}
	//type a struct {
	//	name string
	//	age int
	//}
	//
	//A := a{
	//	"nmnm",
	//	18,
	//}
	//
	//array := make([]a, 0)
	//array = append(array, A)
	//array[0].name = "lplp"
	//
	//fmt.Println(A)
	//fmt.Println(array[0])
	//
	//b := []int {1, 2, 3}
	//c := make([]int, 0)
	//fmt.Println(cap(c))
	//copy(c, b)
	//fmt.Println(cap(c))
	//fmt.Println(len(c))
	//fmt.Println(c)
	//
	//f := make([]map[int]string, 8)
	//fmt.Println(f)

	//s := "ABC"
	//for _, c := range s{
	//
	//	fmt.Println(string(c), reflect.TypeOf(c))
	//}

	//var s []int
	//s = append(s, 1)
	//fmt.Println(s)

	// a 是 nil, 不能添加元素
	//var a map[int]int
	//a[0] = 1
}
